package com.example.qx;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.qx.adapter.adapter;
import com.example.qx.database.data;
import com.example.qx.faxiana.faxian;
import com.example.qx.lei.zhangmi;
import com.example.qx.lianxra.lianxr;
import com.example.qx.qxa.qx;
import com.example.qx.wda.wd;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class zy extends  FragmentActivity {
  private ViewPager viewPager;
    private data data=new data();

 private Button btnqxq,btnqx,btnwd,btnchedui;

    public zy() {
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zy);

        List<Fragment> fragments=new ArrayList<Fragment>();
        fragments.add(new faxian());
        try {
            fragments.add(new lianxr());
        } catch (SQLException | ClassNotFoundException | IllegalAccessException |
                 InstantiationException e) {
            throw new RuntimeException(e);
        }
        try {
            fragments.add(new wd());
        } catch (SQLException | ClassNotFoundException | IllegalAccessException |
                 InstantiationException e) {
            throw new RuntimeException(e);
        }

        fragments.add( new qx());
        adapter adapter=new adapter(getSupportFragmentManager(),fragments);
       viewPager=findViewById(R.id.viewpager);
       viewPager.setAdapter(adapter);
      btnqxq=(Button) findViewById(R.id.faxian);
        btnqx=(Button) findViewById(R.id.qx);
        btnwd=(Button) findViewById(R.id.wd);
        btnchedui=(Button) findViewById(R.id.lianxr);
        btnqxq.setOnClickListener(l);
        btnqx.setOnClickListener(l);
        btnwd.setOnClickListener(l);
        btnchedui.setOnClickListener(l);
        //data.deleteqb(getApplication());
       //data.shuaxin(getApplication());
    }


    View.OnClickListener l=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           int a=0;
            switch (v.getId()){
                case R.id.faxian:
                   a=0;
                    break;
                case R.id.lianxr:
                    a=1;
                    break;
                case R.id.qx:
                    a=3;
                    break;
                case R.id.wd:
                    a=2;
                    break;
            }
            viewPager.setCurrentItem(a);

        }
    };


}